home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1995 April / Internet Tools.iso / ip / ppp / mac / macppp2.0.1-src.hqx / MacPPP 2.0.1 src / ppp.h.source < prev    next >
Encoding:
C/C++ Source or Header  |  1993-10-28  |  25.6 KB  |  781 lines

  1. /*
  2.  * Include file for MacPPP.  Should be pre-compiled with THINK C
  3.  *    to generate the ppp.h file.
  4.  *
  5.  * Copyright 1992-1993 Merit Network, Inc. and The Regents of the
  6.  *  University of Michigan.  Usage of this source code is restricted
  7.  *  to non-profit, non-commercial purposes.  The source is provided
  8.  *  "as-is", without warranty.
  9.  */
  10. #ifndef _PPP_H
  11. #define _PPP_H
  12. /* uncomment this if you want alot of DebugStr statements */
  13. #define PPP_DEBUG_CHECKS(x)    /* DebugStr(x) */
  14. /* uncomment below if you want to log certain events to memory */
  15. /* #define LOG */
  16. #pragma options(check_ptrs)
  17. /*#include <MacHeaders>*/  /* this causes problems */
  18. #include <Serial.h>
  19. #include <Types.h>        /* in MacHeaders */
  20. #include <THINK.h>        /* in MacHeaders */
  21. #include <Memory.h>        /* in MacHeaders */
  22. #include <Fonts.h>        /* in MacHeaders */
  23. #include <LoMem.h>        /* in MacHeaders */
  24. #include <Desk.h>        /* in MacHeaders */
  25. #include <Notification.h>    /* in MacHeaders */
  26. #include <Resources.h>        /* in MacHeaders */
  27. #include <Timer.h>        /* in MacHeaders */
  28. #include <Dialogs.h>    /* in MacHeaders */
  29. #include <asm.h>        /* in MacHeaders */
  30. #include <TextEdit.h>    /* in MacHeaders */
  31. #include <Errors.h>        /* in MacHeaders */
  32. #include <Controls.h>    /* in MacHeaders */
  33. #include <BDC.h>        /* in MacHeaders */
  34.  
  35. #define    uchar(x) ((unsigned char)(x))
  36.  
  37. #include "MacTCPCommonTypes.h"
  38.  
  39. typedef struct LapInfo    LapInfo;
  40. typedef struct PPPiopb    PPPiopb;
  41. typedef struct sdiopb    sdiopb;
  42. typedef struct TMtimer    TMtimer;
  43.  
  44. #include "headers.h"        /* TCP/IP header structures */
  45. #include "slhc.h"
  46.  
  47. /* iopbs to queue transmit requests */
  48. #define    NUMIOPBS 24
  49.  
  50. /* define size for transmit fifo */
  51. #define XMITQLEN 256
  52. #define MAXXMIT 64
  53.  
  54. /* size for receive buffer (to get data from serial driver with PBRead) */
  55. #define RXBUFSIZE 192
  56.  
  57. /* size for receive driver input buffer */
  58. /* this needs to be fairly large for slow Macs to run at higher speeds */
  59. #define SDINBUFLEN 1024
  60.  
  61. #define PARAM_DOWN    0x81
  62. #define PARAM_UP    0x82
  63.  
  64. #define TASK_QUEUED 0x8000
  65.  
  66. /* Lap Transition events */
  67. #define    TransitionOpen  0L
  68. #define    TransitionClose 2L
  69.  
  70. /* define a trap macro for _PBStatus, Immed */
  71. #pragma parameter __D0 PBStatusImmed(__A0)
  72. pascal OSErr PBStatusImmed(ParmBlkPtr paramBlock)
  73.     = 0xA205;
  74.  
  75. #pragma parameter __D0 PBControlImmed(__A0)
  76. pascal OSErr PBControlImmed(ParmBlkPtr paramBlock)
  77.     = 0xA204;
  78.  
  79. /* Basic buffer structure */
  80. struct bufheader {
  81.     b_8        *dataptr;    /* pointer to start of data */
  82.     short    length;        /* length of data */
  83. };
  84.  
  85. #define    YANKBYTE(bufptr)\
  86.  (bufptr->length != 0 ? \
  87.  (bufptr->length--, *bufptr->dataptr++) : -1)
  88.  
  89. #define PPP_IP_PROTOCOL     0x0021
  90. #define PPP_VJ_COMP_PROTOCOL    0x002D
  91. #define PPP_COMPR_PROTOCOL    0x002D
  92. #define PPP_VJ_UNCOMP_PROTOCOL    0x002F
  93. #define PPP_UNCOMP_PROTOCOL    0x002F
  94. #define PPP_IPCP_PROTOCOL    0x8021
  95. #define PPP_LCP_PROTOCOL    0xC021
  96. #define PPP_PAP_PROTOCOL    0xC023
  97. #define HDLC_ALL_ADDR    0xff    /* HDLC all-station */
  98. #define HDLC_UI            0x03    /* HDLC Unnumbered Information */
  99. #define PPP_HDR_LEN    4    /* Max bytes for PPP/HDLC envelope header */
  100.  
  101. /* character defines */
  102. #define ENTER 3
  103. #define RETURN 13
  104. #define TAB 9
  105. #define BACKSPACE 8
  106.  
  107. /*
  108.  *  Timer
  109.  */
  110.  
  111. #define NULLTIMER    (struct TMtimer *)0
  112.  
  113. struct TMtimer
  114. {
  115.     TMTask            atm;        /* time manager task struct */
  116.     long            duration;    /* millisecond delay (must be positive) */
  117.     struct fsm_s    *fsm_p;        /* pointer to fsm to which this belongs */
  118.     voidProcPtr        proc;        /* procedure to execute on timeout */
  119.     b_8                state;        /* state of the this timer */
  120. };
  121.  
  122. /* Timer states */
  123. #define TIMER_STOP    0
  124. #define TIMER_RUN    1
  125. #define TIMER_EXPIRE    2
  126.  
  127. struct TMprocess
  128. {
  129.     TMTask            atm;
  130.     union {
  131.         LapInfo            *lap;        /* place to save our lap pointer */
  132.         struct fsm_s    *fsm_p;        /* fsm pointer */
  133.     } tmsavptr;
  134. };
  135.  
  136. /*
  137.  *  PPP characters
  138.  */
  139.  
  140. enum {    PPP_FLAG    =   0x7E,   /* Opening/closing frame flag */
  141.     PPP_ESCAPE    =   0x7D   /* escape next character */
  142. };
  143.  
  144. typedef enum { s_Idle, s_Data, s_Escape, 
  145.                   s_Init, s_Finish, s_SendFCS, s_Loopback } HDLCState;
  146.  
  147. #define FCS_INIT    0xFFFF
  148. #define FCS_TERM    0xF0B8
  149. /* config packet header */
  150. struct config_hdr {
  151.     b_8 code;
  152. #define CONFIG_REQ     1
  153. #define CONFIG_ACK     2
  154. #define CONFIG_NAK     3
  155. #define CONFIG_REJ     4
  156. #define TERM_REQ     5
  157. #define TERM_ACK     6
  158. #define CODE_REJ     7
  159. #define PROT_REJ     8
  160. #define ECHO_REQ     9
  161. #define ECHO_REPLY    10
  162. #define DISCARD_REQ    11
  163.  
  164.     b_8 id;
  165.     b_16 len;
  166. };
  167. #define CONFIG_HDR_LEN    4    /* Length of config packet header */
  168.  
  169. /* config option header */
  170. struct option_hdr {
  171.     b_8 type;        /* protocol dependant types */
  172.     b_8 len;
  173. };
  174. #define OPTION_HDR_LEN    2    /* Length of option header */
  175.  
  176. /* Supported Configuration Protocol index */
  177. enum { Lcp, Pap, IPcp, fsmi_Size };
  178.  
  179. /* Protocol Constants needed by State Machine */
  180. struct fsm_constant_s {
  181.     b_16    protocol;        /* Protocol number */
  182.     b_8        fsmi;            /* Finite State Machine index */
  183.     b_8        try_req;        /* # of tries for config request */
  184.     b_8        try_nak;        /* # tries for nak substitutes */
  185.     b_8        try_terminate;    /* # tries for terminate */
  186.     b_8        *option_lengths;    /* ptr to array of option lengths */
  187.     b_8        option_limit;    /* # of options recognized */
  188.     b_8        timeout;        /* Time for timeouts (seconds)*/
  189. };
  190.  
  191. /* FSM states */
  192. enum { fsmINITIAL, fsmSTARTING, fsmCLOSED, fsmSTOPPED, fsmCLOSING, fsmSTOPPING,
  193.         fsmREQ_Sent, fsmACK_Rcvd, fsmACK_Sent, fsmOPENED, fsmState_Size };
  194.  
  195. /* State Machine Control Block */
  196. struct fsm_s {
  197.     b_8        state;            /* FSM state */
  198.     b_8        lastid;            /* ID of last REQ we sent */
  199.     b_8        retry;            /* counter for timeouts */
  200.     b_8        retry_nak;        /* counter for naks of requests */
  201.     LapInfo *lap;            /* place to stuff lap pointer */
  202.     struct    TMtimer timer;
  203.     struct    fsm_constant_s pdc;    /* protocol dependent constants */
  204.     void    *pdv;            /* pointer to protocol dependent variables */
  205. };
  206.  
  207. /* Link Phases */
  208. enum {
  209.     pppDEAD = 0,    /* Link Dead, Waiting for physical layer */
  210.     pppESTABLISH,    /* Link Establishment (LCP) phase */
  211.     pppAUTHENTICATE,    /* Authentication Phase */
  212.     pppNETWORK,        /* Network-Layer Protocol Phase */
  213.     pppTERMINATE,    /* Link Termination Phase */
  214.     pppPhase_Size
  215. };
  216.  
  217.                     /* LCP option types */
  218. #define LCP_MRU            0x01
  219. #define LCP_ACCM        0x02
  220. #define LCP_AUTHENT        0x03
  221. #define LCP_QUALITY        0x04
  222. #define LCP_MAGIC        0x05
  223. #define LCP_PFC            0x07
  224. #define LCP_ACFC        0x08
  225. #define LCP_OPTION_LIMIT    0x08    /* highest # we can handle */
  226. #define LCP_N_MRU        (1 << LCP_MRU)
  227. #define LCP_N_ACCM        (1 << LCP_ACCM)
  228. #define LCP_N_AUTHENT    (1 << LCP_AUTHENT)
  229. #define LCP_N_MAGIC        (1 << LCP_MAGIC)
  230. #define LCP_N_QUALITY    (1 << LCP_QUALITY)
  231. #define LCP_N_PFC        (1 << LCP_PFC)
  232. #define LCP_N_ACFC        (1 << LCP_ACFC)
  233.  
  234. /* Table for LCP configuration requests */
  235. struct lcp_value_s {
  236.     b_16    mru;            /* Maximum Receive Unit */
  237.     b_16    authentication;    /* Authentication protocol */
  238.     b_32    accm;            /* Async Control Char Map */
  239.     b_32    magic_number;    /* Magic number value */
  240. };
  241.  
  242. /* for test purposes, accept anything we understand in the NAK */
  243. #define LCP_NEG LCP_N_MRU | LCP_N_ACCM | LCP_N_AUTHENT | LCP_N_PFC | LCP_N_ACFC | LCP_N_MAGIC
  244.  
  245. /* Other configuration option values */
  246. #define LCP_ACCM_DEFAULT    0xffffffffL
  247. #define LCP_MRU_DEFAULT    1500
  248. #define LCP_MRU_HI    1500    /* High MRU limit */
  249. #define LCP_MRU_LO    128        /* Lower MRU limit */
  250.  
  251. #define PPP_OVERHEAD 8        /* room for addr, cntl, protocol and 32-bit FCS */
  252. #define    PPP_BUFSIZE LCP_MRU_HI + PPP_OVERHEAD /* size of buf for PPP packet */
  253.  
  254. #define LCP_NAK_TRY    10        /* NAK attempts */
  255. #define LCP_TERM_TRY 2        /* tries on TERM REQ */
  256.  
  257. /* PAP Parameters */
  258. #define PAPMESSLEN 128
  259. #define PAPUSERLEN 32
  260. #define PAPPASSLEN 32
  261.     /* PAP control block */
  262. struct pap_s {
  263.     b_8        username[PAPUSERLEN];    /* Username for REQ */
  264.     b_8        password[PAPPASSLEN];    /* Password for REQ */
  265.     b_8        message[PAPMESSLEN];    /* message from last ACK/NAK */
  266.     b_8        IOFlag;            /* flag to indicate userio necessary */
  267. };
  268.  
  269.  
  270.                     /* IPCP option types */
  271. #define IPCP_COMPRESS        0x02
  272. #define IPCP_ADDRESSES        0x01
  273. #define IPCP_ADDRESS        0x03    /* newer IP ADDRESS negotiation */
  274. #define IPCP_OPTION_LIMIT    0x03    /* highest # we can handle */
  275. #define IPCP_N_ADDRESS        (1 << IPCP_ADDRESS)
  276. #define IPCP_N_COMPRESS        (1 << IPCP_COMPRESS)
  277. #define IPCP_N_ADDRESSES    (1 << IPCP_ADDRESSES)
  278.  
  279. /* Table for IPCP configuration requests */
  280. struct ipcp_value_s {
  281.     b_32    address;        /* address for this side */
  282.     b_32    other;            /* address for other side */
  283.     b_16    compression;    /* Compression protocol */
  284.     b_16    slots;            /* Slots (0-n)*/
  285.     b_8        slot_compress;    /* Slots may be compressed (flag)*/
  286. };
  287.  
  288. /* for test purposes, accept anything we understand */
  289. #define IPCP_NEG  IPCP_N_ADDRESSES | IPCP_N_COMPRESS | IPCP_N_ADDRESS;
  290.  
  291. #define IPCP_SLOT_DEFAULT     16    /* Default # of slots */
  292. #define IPCP_SLOT_HI         16    /* Maximum # of slots (preallocated) */
  293. #define IPCP_SLOT_LO          1    /* Minimum # of slots */
  294. #define IPCP_SLOT_COMPRESS    0x01    /* May compress slot id */
  295. #define    MAXSLOTS IPCP_SLOT_HI    /* determine how much space to get */    
  296.  
  297. #define IPCP_NAK_TRY    10        /* NAK attempts */
  298. #define IPCP_TERM_TRY    2        /* tries on TERM REQ */
  299.  
  300. /*
  301.  *    local.want:    Options to request and desired values
  302.  *    local.will:    Options to accept in a NAK from remote.
  303.  *    local.work:    Options currently being negotiated.
  304.  *            Value is valid only when negotiate bit is set.
  305.  *    remote.want:    Options to suggest by NAK if not present in REQ.
  306.  *    remote.will:    Options to accept in a REQ from remote.
  307.  *    remote.work:    Options currently being negotiated.
  308.  *            Value is valid only when negotiate bit is set.
  309.  */
  310.  
  311. union value_s {
  312.     struct    lcp_value_s lcp_option;
  313.     struct    ipcp_value_s ipcp_option;
  314. };
  315.  
  316. struct option_s {
  317.     b_16            will_negotiate, want_negotiate;
  318.     union value_s    want;
  319.     b_16            work_negotiate;
  320.     union value_s    work;
  321. };
  322.  
  323. struct proto_s {
  324.     struct    option_s local, remote;
  325. };
  326.  
  327.  /* structure to queue writes */
  328.  
  329. struct PPPiopb {
  330.     QElemPtr    qLink;        /* next in queue */
  331.     short        qType;        /* qType field */
  332.     struct bufheader *bufptr;        /* ptr to buffer */
  333.     struct ipbuf    *ipbuf;        /* ptr to ipbuf */
  334. };
  335.  
  336. /* Data structure for PPP Preferences file */
  337. /* Note: This struct MUST map into the option_s structure !! */
  338.  
  339. struct lcp_will_want {
  340.     b_16    will_negotiate, want_negotiate;
  341.     struct    lcp_value_s want;
  342. };
  343.  
  344. struct lcpconfig {
  345.     struct lcp_will_want local, remote;
  346.     b_8        req_tries;
  347.     b_8        timeout;
  348. };
  349.  
  350. struct ipcp_will_want {
  351.     b_16    will_negotiate, want_negotiate;
  352.     struct    ipcp_value_s want;
  353. };
  354.  
  355. struct ipcpconfig {
  356.     struct ipcp_will_want local, remote;
  357.     b_8        req_tries;
  358.     b_8        timeout;
  359. };
  360.  
  361. #define MAXSLEN 42        /* max string length */
  362. #define NUMCOMMANDS 8    /* number of strings */
  363. #define PREF_VERSION 3    /* version of prefs file */
  364. #define NUMCONFIGS 4    /* number of configurations */
  365. struct ppp_pref {
  366.     b_16    version;        /* version of Preferences file */
  367.     b_8        portname[32];    /* port name (from CommToolBox) */
  368.     Boolean    hangup;            /* send modem hangup command on close */
  369.     Boolean    use_pulse;        /* use pulse for dialing */
  370.     Boolean quiet;            /* Quiet mode flag */
  371.     Boolean use_term;        /* bring up a terminal window on connection establishment */
  372.     b_16    timeout;        /* idle timeout (minutes), 0 = none */
  373.     b_16    echo;            /* PPP LCP echo interval  0 = off */
  374.     b_16    active_config;    /* active config index */
  375.     b_16    max_config;        /* maximum conifg index */
  376.     b_16    echo_tries;        /* number of echos before down */
  377.     b_16    max_window;        /* maximum window size */
  378. };
  379.  
  380. struct ppp_config {
  381.     struct    lcpconfig    lcpconf;
  382.     struct    ipcpconfig    ipcpconf;
  383.     b_8        pap_retries;                /* number of tries for PAP */
  384.     b_8        pap_timeout;            /* timeout for PAP */
  385.     b_16    connecttimeout;
  386.     b_16    waittimeout;
  387.     b_16    baudrate;        /* port speed */
  388.     b_8        flags;
  389. #define CTSBIT 0x1
  390. #define RTSBIT 0x2
  391. #define FLOWBITS CTSBIT+RTSBIT
  392. #define USE_PULSE 0x4
  393.     b_8        config_name[MAXSLEN + 1];        /* configuration name */
  394.     b_8        defaultid[MAXSLEN + 1];        /* add one for length byte */
  395.     b_8        defaultpw[MAXSLEN + 1];
  396.     b_8        modeminit[MAXSLEN + 1];
  397.     b_8        phonenum[MAXSLEN + 1];
  398.     struct {
  399.         Boolean    sendout;        /* should we send or wait for this string */
  400.         Boolean addreturn;        /* add a carriage return to end of string */
  401.         b_8        scriptstr[MAXSLEN + 1];    /* script string */
  402.     } commands[NUMCOMMANDS];
  403. };
  404.  
  405. struct IPCONFIG {
  406.     long        version;
  407.     long        flags;
  408.     long        dfl_ip_addr;
  409.     long        dfl_net_mask;
  410.     long        dfl_broadcast_mask;
  411.     long        dfl_gateway_addr;
  412.     unsigned char    server_lap_address[8];
  413.     long        configIPAddr;
  414.     long        configNetMask;
  415.     long        dfl_dyn_low;
  416.     long        dfl_dyn_high;
  417.     char        dfl_zone[33];        /* ### */
  418. /* align to word */
  419.     Byte        load;
  420.     Byte        admin;
  421.     Byte        netLock;
  422.     Byte        subnetLock;
  423.     Byte        nodeLock;
  424.     Byte        filler1;
  425.     long        activeLap;
  426.     long        slot;
  427.     char        filename[33];        /* ### */
  428. };
  429.  
  430. struct icmpEchoInfo {
  431.     unsigned long    echoRequestOut;    /* time when echo req. went out */
  432.     unsigned long    echoReplyIn;    /* time when echo reply received */
  433.     struct rdsEntry    echoedData;    /* data received in response */
  434.     Ptr        options;    /* IP Options */
  435.     unsigned long    userDataPtr;    /* userDataPtr for app stuff */
  436. };
  437.  
  438. typedef struct ipbuf {
  439.     IOParam        iop;        /* MAC OS I/O Param block */
  440.     struct icmpEchoInfo    echoInfo;    /* ping stuff */
  441.     struct ipbuf    *segipb;    /* pointer to segment's IPB if fragmented */
  442.     struct LapInfo    *lap;        /* LAP pointer */
  443.     ProcPtr        lap_ioc;     /* local net completion routine */
  444.     ProcPtr        ip_ioc;        /* IP completion routine */
  445.     ProcPtr        tp_ioc;        /* transport completion routine */
  446.     ProcPtr        data_ioc;    /* data IOC */
  447.     struct wdsEntry    laphdr;        /* local net header */
  448.     struct wdsEntry    ip;        /* IP header */
  449.     struct wdsEntry    tp;        /* TCP/UDP or ICMP header */
  450.     struct wdsEntry    data;        /* TCP/UDP data */
  451.     struct wdsEntry    d1;
  452.     struct wdsEntry    d2;
  453.     struct wdsEntry    d3;
  454.     struct wdsEntry    d4;        /* 8 wds entries plus 0 terminator */
  455.     short        flag;        /* zero terminator to WDS */
  456.     char        packet[];    /* start of variable length pkt */
  457. } ipbuf;
  458.  
  459. struct rdStruct {
  460.     ProcPtr    ph_rp;        /* pointer to "ReadPacket" routine (a4)    */
  461.     ProcPtr    ph_rr;        /* pointer to "ReadRest" routine 2(a4)    */
  462.     long    ph_bytesleft;    /* number of bytes left to read    */
  463.     union {
  464.         struct {    /* storage for standard AppleTalk LAP protocol handler */
  465.             long    phb_a4;        /* used by driver    */
  466.             long    phb_a0;        /* used by driver    */
  467.             long    phb_a1;        /* used by driver    */
  468.             long    phb_a2;        /* used by driver    */
  469.             } phb;
  470.         struct {    /* storage for a buffered LAP interface */
  471.             b_8    *lnb_ptr;    /* pointer to next byte to get from buffer    */
  472.             } lnb;
  473.         struct {    /* storage for a reassembled IP packet */
  474.             struct fragment    *rsmb_fragbuffer;    /* buffer to fragment data buffer */
  475.             b_8    *rsmb_ptr;    /* pointer to next byte to get from buffer */
  476.             long    rsmb_bytesleft;    /* number of bytes left in this buffer */
  477.             long    rsmb_byteoffset;/* offset of next byte in rsm'd pkt */
  478.             } rsm;
  479.         } rdsparm;
  480.     Byte    lapBroadcast;    /* LAP-level broadcast */
  481.     Byte    ipBroadcast;    /* IP-level broadcast */
  482.     struct LapInfo    *lap;
  483.     struct wdsEntry    laphdr;    /* local net header */
  484.     struct wdsEntry    ip;    /* ip header !!! (IPwdsEntry) ???*/
  485.     struct wdsEntry    tp;    /* TCP/UDP or ICMP header */
  486.     struct wdsEntry    data;    /* TCP/UDP data */
  487. };
  488.  
  489. struct sdiopb {
  490.     IOParam        iop;    /* IOPB for serial driver use */
  491.     LapInfo        *lap;    /* ptr to LapInfo */
  492.     };
  493.     
  494. typedef unsigned long (*longProcPtr)();
  495.  
  496. #define BUFOFFSET sizeof(struct bufheader) + sizeof(struct ipheader) + sizeof(struct tcpheader)
  497. #define    BUFFERSIZE PPP_BUFSIZE + BUFOFFSET
  498. #define NUMBUFFERS 4    /* number of buffers to allocate */
  499. #define LCP_ECHO_BUFSIZE 12 /* buffer size for lcp echo requests */
  500.  
  501. struct LapInfo {
  502.     b_32        cur_ip_addr;    /* LAP's IP address */
  503.     b_32        cur_net_mask;    /* LAP's IP net-mask */
  504.     b_32        ip_broadcast_addr;    /* IP's broadcast address */
  505.     struct IPCONFIG    lc;        /* copy of IP LAP cnfg rsrc */
  506.     OSErrProcPtr    lapInit;    /* ptr to LAP init routine */
  507.     OSErrProcPtr    lapOpen;    /* LAP open rtn */
  508.     OSErrProcPtr    lapClose;    /* LAP close rtn */
  509.     voidProcPtr        lapUnload;    /* LAP unload rtn, undoes lapInit */
  510.     OSErrProcPtr    lapAttach;    /* LAP attach PH rtn */
  511.     OSErrProcPtr    lapDetach;    /* LAP detach PH rtn */
  512.     OSErrProcPtr    lapOutput;    /* LAP output rtn */
  513.     OSErrProcPtr    lapControl;    /* LAP control rtn */
  514.     voidProcPtr        lapFault;    /* LAP fault isolation rtn */
  515.     OSErrProcPtr    lapStatistics;    /* LAP statistic reading rtn */
  516.     voidProcPtr        lapConfigure;    /* LAP configuration rtn */
  517.     BooleanProcPtr    lapProbe;    /* send a LAP-specific addr probe pkt */
  518.     BooleanProcPtr    lapRegister;    /* register our IP address on net */
  519.     voidProcPtr        lapFindGateway;    /* LAP-specific way to find gateway  */
  520.     BooleanProcPtr    lapGwyCheck;    /* LAP-specific way to gateway is up */
  521. /* IP Parameters */
  522.     ip_addr        dfl_dns_addr;    /* addr of DNS from config protocol */
  523.     Handle        dnslHndl;    /* handle to DNS config rsrc */
  524.     Ptr            dnsCache;    /* ptr to DNS cache area */
  525.     long        dnsCacheSize;    /* size of cache in bytes */
  526. /* LAP Parameters */
  527.     long        headerSize;    /* LAP header space required */
  528.     long        trailerSize;    /* LAP trailer space required */
  529.     long        outMaxPacketSize;    /* max output packet size */
  530.     long        inMaxPacketSize;    /* max input packet size */
  531.     long        maxDataSize;    /* max size of data packet */
  532.     long        numConnections;    /* number of separate net connections */
  533.     unsigned long    versionFlags;    /* version number flags */
  534.     voidProcPtr    ip_ph;        /* ptr to IP protocol handler */
  535.     Ptr            ipGlobals;    /* ptr to IP's A5 */
  536.     short        link_unit;    /* unit number of link driver */
  537.     Byte        addressConflict;    /* TRUE is address conflict */
  538.     long        lapType;    /* IP LAP hardware type # */
  539.     long        lapAddrLength;    /* size of LAP address field */
  540.     unsigned char     *lapAddrPtr;    /* ptr to LAP address field */
  541.     unsigned long    reserved;    /* MacTCP reserved field */
  542.     /* PPP specific storage */
  543.     Boolean        ok_to_xmit;    /* ok to transmit on serial port */
  544.     Boolean        term_mode;    /* terminal emulation flag */
  545.     Boolean        needTxPrime;    /* transmit routine needs to be primed */
  546.     Boolean        HasDeferredTasks;    /* indicates if Deferred Tasks available */
  547.     short        serinrefnum;    /* serial input ref num */
  548.     short        seroutrefnum;    /* serial output ref num */
  549.     b_8            rxbuf[RXBUFSIZE];    /* small receive buffer to get data from driver */
  550.     longProcPtr    transProc;    /* ptr to transition Proc */
  551.     longProcPtr savProc;    /* place to save a copy of transition proc pointer */
  552.     Ptr            LapA4;        /* holder for LAP's A4 */
  553.     HDLCState    read_state;    /* state of PPP receiver */
  554.     HDLCState    write_state;    /* state of PPP transmitter */
  555.     short        echo_count;    /* count of outstanding LCP echo requests */
  556.     short        idle_timer;    /* number of idle minutes */
  557.     short        writerr;    /* error on write. Who knows what */
  558.     short        readerr;    /* receiver errors */
  559.     OSErr        lasterr;    /* rc of last PBRead != noErr */
  560.     short        outofiopbs;    /* write failed; too many dgs q'd */
  561.     short        faults;        /* PPPFault was called. */
  562.     short        OutofBuffers;    /* # of getbuffer failures */
  563.     long        OutTxOctetCount;/* # octets sent */
  564.     long        OutOpenFlag;    /* # of open flags sent */
  565.     short        OutError;        /* # packets with error on send */
  566.     long        InRxOctetCount;    /* # octets received */
  567.     long        InOpenFlag;        /* # of open flags */
  568.     short        InUnknown;        /* # unknown packets received */
  569.     short        InCheckSeq;        /* # packets with bad check sequence */
  570.     short        InFramingErr;    /* # framing errors */
  571.     short        InError;        /* # packets with other error */
  572.     short        InIdleToss;        /* non-flag chars while Idle */
  573.     short        InHeader;        /*  Header errors */
  574.     short        InFrameOvr;        /* frame overrun */
  575.     short        InSoftOvr;        /* software overrun */
  576.     short        InHardOvr;        /* hardware overrun */
  577.     struct bufheader    *bufptr; /* current buffer for receive data */
  578.     b_8            *rddata;        /* pointer to end of data in rcv. buffer */
  579.     b_8            xbuf[8];        /* small buffer for copying to fifo */
  580.     struct { 
  581.         b_8        block[BUFFERSIZE];
  582.     } blockarray[NUMBUFFERS];    /* storage for memory blocks */
  583.     struct bufheader *buflist;    /* pointer to buffer list */
  584.     struct {                    /* a small buffer for LCP echo requests */
  585.         struct bufheader header;    /* a fake header for the buffer */
  586.         b_8        buffer[LCP_ECHO_BUFSIZE];    /* the actual buffer */
  587.     } lcp_echo_buf;
  588.     QHdr        out_q;            /* q of packets to write */
  589.     QHdr        pppbq;            /* Q of free PPPiopbs */
  590.     PPPiopb        *active;        /* current PPPiopb to transmit */
  591.     PPPiopb        pppiopbs[NUMIOPBS];    /* define storage for iopbs */
  592.     sdiopb        w_iopb;            /* IOPB for serial port writes */
  593.     sdiopb        r_iopb;            /* IOPB for serial port reads */
  594.     cntrlParam    stat_pb;        /* cntrlParam block for status calls */
  595.     struct rdStruct        rds;    /* for passing to ip layer */
  596.     struct ppp_pref    prefdata;    /* Data from Preferences file */
  597.     struct ppp_config configdata;    /* more preferences */
  598.     b_32        PPP_RecvACM;    /* Async Control maps */
  599.     b_32        PPP_XmitACM;
  600.     b_32        PPP_activeACM;    /* current active transmit ACCM */
  601.     b_16        fcstab[256];    /* FCS table for quicker FCS's */
  602.     b_16        XmitFCS;        /* FCS for current transmit frame */
  603.     b_16        RecvFCS;        /* FCS for current rx frame */
  604.     struct    NMRec        closenmtask;    /* Notification task record to close link */
  605.     struct    TMprocess    rxp_task;    /* receive processing task structure */
  606.     struct    TMprocess    txp_task;    /* transmit process task structure */
  607.     struct  TMprocess    echo_task;    /* LCP echo process */
  608.     struct    TMprocess    timeout_task;    /* idle timeout process */
  609.     struct    DeferredTask  {
  610.         QElemPtr    qLink;
  611.         short        qType;
  612.         short        dtFlags;
  613.         ProcPtr        dtAddr;
  614.         long        dtParm;
  615.         long        dtReserved;
  616.     }    defer_tx, defer_rx, defer_txcomplete;
  617.     b_8        sdinbuf[SDINBUFLEN]; /* input buffer for serial driver receive */
  618.     b_16    XmitQHead;            /* transmit queue head index */
  619.     b_16    XmitQTail;            /* transmit queue tail index */
  620.     b_16    XmitQSize;            /* transmit queue size */
  621.     b_8        XmitQ[XMITQLEN];    /* transmit queue */
  622.     struct proto_s    lcp_i, ipcp_i;
  623.     struct pap_s    pap_i;
  624.     b_8        ppp_phase;            /* phase of link initialization */
  625.     b_8        ppp_id;                /* id counter for connection */
  626.     b_32    ppp_upsince;        /* Timestamp when Link Opened */
  627.     b_8        ppp_flags;
  628. #define PPP_AP_REMOTE    0x01    /* remote authentication */
  629. #define ECHO_FAIL        0x02    /* LCP echo timeout */
  630. #define IDLE_TIMEOUT    0x04    /* idle timeout */
  631. #define CLOSE_PPP        0x08    /* close PPP flag */
  632.     struct fsm_s ppp_fsm[fsmi_Size];    /* finite state machines */
  633.     struct slcompress    comp;
  634.     struct cstate    rcvslots[MAXSLOTS],txslots[MAXSLOTS];
  635.     b_8        *lcp_option_length_p; /* lcp option lengths */
  636.     struct    lcp_value_s *lcp_default_p;    /* pointer to default option values */
  637.     b_8        *ipcp_option_length_p; /* ipcp options lengths */
  638.     struct    ipcp_value_s *ipcp_default_p;    /* pointer to default option values */
  639. #ifdef LOG
  640.     int        *logp;
  641.     int        log[5*100];
  642.     int        logend;
  643.     int        cushion[10];
  644. #endif
  645. };
  646.  
  647. typedef struct LapStats {
  648.     short    ifType;
  649.     char    *ifString;
  650.     short    ifMaxMTU;
  651.     long    ifSpeed;
  652.     short    ifPhyAddrLength;
  653.     char    *ifPhysicalAddress;
  654.     union {
  655.             char *noarp;
  656.             } AddrXlation;
  657.     short    slotNumber;
  658. };
  659.     
  660. /* Prototypes and declarations for routines */
  661.  
  662. /* lap.c */
  663. OSErr     PPPInit(    LapInfo *, longProcPtr);
  664. OSErr     PPPOpen(    LapInfo *);
  665. OSErr     PPPClose(    LapInfo *);
  666. void    PPPUnload(    LapInfo *);
  667. OSErr     PPPAttachPH(    LapInfo *, voidProcPtr);
  668. OSErr     PPPDetachPH(    LapInfo *);
  669. OSErr     PPPWrite(    LapInfo *, ip_addr, struct ipbuf *);
  670. OSErr     PPPControl(    LapInfo *);
  671. void     PPPFault(    LapInfo *, ip_addr);
  672. void     PPPConfigure(    LapInfo *);
  673. Boolean    PPPProbe(    LapInfo *, ip_addr);
  674. Boolean    PPPRegister(    LapInfo *);
  675. void    PPPFindGW(    LapInfo *);
  676. OSErr     PPPStatistics(    LapInfo *, struct LapStats *);
  677.  
  678. /* misc.c: */
  679. void    AppendStr(b_8 *, b_8 *);
  680. struct bufheader *getbuffer();
  681. void    release(struct bufheader *);
  682. void    makeroom(struct bufheader *, b_16);
  683. b_16    yankbuf(struct bufheader *, b_8 *, b_16);
  684. short    yankbyte(struct bufheader *);    /* returns -1 if nothing */
  685. long    yank16(struct bufheader *);    /* returns -1 if nothing */
  686. b_32    yank32(struct bufheader *);    /* returns  0 if nothing */
  687. short    bytecmp(b_8 *, b_8 *, short);
  688. b_16    get16(b_8 *);
  689. b_32    get32(b_8 *);
  690. b_8        *put16(b_8 *, b_16);
  691. b_8        *put32(b_8 *, b_32);
  692. void    tcp_window_fix(LapInfo *, struct bufheader *);
  693.  
  694. /* fsm.c */
  695. void    htoncnf(struct config_hdr *, struct bufheader *);
  696. short    ntohcnf(struct config_hdr *, struct bufheader *);
  697. short    ntohopt(struct option_hdr *, struct bufheader *);
  698.  
  699. short    fsm_sendtermreq(struct fsm_s *);
  700. short    fsm_sendtermack(struct fsm_s *, b_8);
  701. void    fsm_reset(struct fsm_s *);
  702. void    fsm_tld(struct fsm_s *);
  703. void    fsm_tlu(struct fsm_s *);
  704. void    fsm_tlf(struct fsm_s *);
  705. void    fsm_tls(struct fsm_s *);
  706. void    fsm_no_action(struct fsm_s *);
  707. short    fsm_no_check(struct fsm_s *, struct config_hdr *, struct bufheader *);
  708. void    fsm_log(struct fsm_s *, char *);
  709. void    fsm_timer(struct fsm_s *);
  710. void    fsm_timeout(void);
  711. short    fsm_send(struct fsm_s *, b_8, b_8, struct bufheader *);
  712. short    fsm_sendreq(struct fsm_s *);
  713. void    fsm_proc(struct fsm_s *, struct bufheader *);
  714. void    fsm_open(struct fsm_s *);
  715. void    fsm_down(struct fsm_s *);
  716. void    fsm_close(struct fsm_s *);
  717. void    fsm_init(struct fsm_s *);
  718.  
  719. /* ppp.c */
  720. void    ppp_ready(LapInfo *);
  721. void    ppp_init(LapInfo *);
  722. short    ppp_iostatus(LapInfo *, short);
  723. void    htonppp(LapInfo *, b_16, struct bufheader *);
  724. short    proc_request(struct fsm_s *, struct config_hdr *, struct bufheader *);
  725. short    proc_ack(struct fsm_s *, struct config_hdr *, struct bufheader *);
  726. short    proc_nak(struct fsm_s *, struct config_hdr *, struct bufheader *);
  727. short    proc_reject(struct fsm_s *, struct config_hdr *, struct bufheader *);
  728. short    option_check(struct bufheader *, struct fsm_s *,
  729.                             struct option_hdr *, short);
  730. void    makeoptions(struct fsm_s *, struct bufheader *, union value_s *, b_16);
  731. void    add_option(struct fsm_s *, struct bufheader *, union value_s *,
  732.                         b_8, b_8, struct bufheader *);
  733. struct bufheader *makereq(struct fsm_s *);
  734.  
  735. /* link.c */
  736. void    link_open(LapInfo *);
  737. void    link_close();
  738.  
  739. /* asmutil.c */
  740. void    bzero(b_8 *, short);
  741. void    SetLAPPtr(LapInfo *);
  742. LapInfo    *GetLAPPtr(void);
  743. long    seta5(long);
  744. long    geta5(void);
  745. long    seta4(long);
  746. long    geta4(void);
  747. short    set_sr(short);
  748. short    get_sr(void);
  749.  
  750. /* io.c */
  751. void    RcvDeferred(void);
  752. void    XmtDeferred(void);
  753. void    TxCDeferred(void);
  754. ProcPtr hdlcrioc(void);
  755. ProcPtr    hdlcwioc(void);
  756. OSErr    QueueFrame(LapInfo *, struct bufheader *, struct ipbuf *);
  757. PPPiopb *get_iopb(LapInfo *);
  758. OSErr    readpkt(struct rdStruct *, Ptr, long);
  759. long    readrest(struct rdStruct *, Ptr, long);
  760. void    rcvip(LapInfo *, struct bufheader *);
  761. OSErr    xmit(sdiopb *, b_8 *, long);
  762. void    ProcRcvPPP(void);
  763. void    ProcXmtPPP(LapInfo *);
  764. void    XmtTMProc(void);
  765. void    IOCompleted(LapInfo *, struct ipbuf *);
  766. void    SerComplete(void);
  767. void    SerReadDone(void);
  768.  
  769. /* pap.c */
  770. short    pap_remote(LapInfo *);
  771. void    pap_down(struct fsm_s *);
  772. void    pap_proc(struct fsm_s *, struct bufheader *);
  773. OSErr    pap_userio(struct fsm_s *);
  774.  
  775. /* timer.c */
  776. void    set_timer(TMtimer *, struct fsm_s *, voidProcPtr);
  777. void    start_timer(TMtimer *);
  778. void    stop_timer(TMtimer *);
  779.  
  780. #endif /* _PPP_H */
  781.